home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / cmds / mig / dist / type.h < prev    next >
Encoding:
C/C++ Source or Header  |  1992-01-28  |  10.0 KB  |  268 lines

  1. /* 
  2.  * Mach Operating System
  3.  * Copyright (c) 1991,1990 Carnegie Mellon University
  4.  * All Rights Reserved.
  5.  * 
  6.  * Permission to use, copy, modify and distribute this software and its
  7.  * documentation is hereby granted, provided that both the copyright
  8.  * notice and this permission notice appear in all copies of the
  9.  * software, derivative works or modified versions, and any portions
  10.  * thereof, and that both notices appear in supporting documentation.
  11.  * 
  12.  * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
  13.  * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
  14.  * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
  15.  * 
  16.  * Carnegie Mellon requests users of this software to return to
  17.  * 
  18.  *  Software Distribution Coordinator  or  Software.Distribution@CS.CMU.EDU
  19.  *  School of Computer Science
  20.  *  Carnegie Mellon University
  21.  *  Pittsburgh PA 15213-3890
  22.  * 
  23.  * any improvements or extensions that they make and grant Carnegie Mellon
  24.  * the rights to redistribute these changes.
  25.  */
  26. /*
  27.  * HISTORY
  28.  * $Log:    type.h,v $
  29.  * Revision 2.7  92/01/14  16:46:51  rpd
  30.  *     Added itCheckFlags, itCheckDeallocate, itCheckIsLong.
  31.  *     Removed itServerCopy.
  32.  *     [92/01/09            rpd]
  33.  * 
  34.  * Revision 2.6  92/01/03  20:30:23  dbg
  35.  *     Add flCountInOut.
  36.  *     [91/11/11            dbg]
  37.  * 
  38.  * Revision 2.5  91/08/28  11:17:30  jsb
  39.  *     Removed itMsgKindType.
  40.  *     [91/08/12            rpd]
  41.  * 
  42.  * Revision 2.4  91/07/31  18:11:22  dbg
  43.  *     Add flServerCopy.
  44.  *     [91/06/05            dbg]
  45.  * 
  46.  *     Add itIndefinite.
  47.  *     [91/04/10            dbg]
  48.  * 
  49.  *     Change itDeallocate to an enumerated type, to allow for
  50.  *     user-specified deallocate flag.
  51.  * 
  52.  *     Add itCStringDecl.
  53.  *     [91/04/03            dbg]
  54.  * 
  55.  * Revision 2.3  91/02/05  17:56:13  mrt
  56.  *     Changed to new Mach copyright
  57.  *     [91/02/01  17:56:19  mrt]
  58.  * 
  59.  * Revision 2.2  90/06/02  15:05:59  rpd
  60.  *     Created for new IPC.
  61.  *     [90/03/26  21:14:28  rpd]
  62.  * 
  63.  * 07-Apr-89  Richard Draves (rpd) at Carnegie-Mellon University
  64.  *    Extensive revamping.  Added polymorphic arguments.
  65.  *    Allow multiple variable-sized inline arguments in messages.
  66.  *
  67.  * 16-Nov-87  David Golub (dbg) at Carnegie-Mellon University
  68.  *    Changed itVarArrayDecl to take a 'max' parameter.
  69.  *    Added itDestructor.
  70.  *
  71.  *  18-Aug-87    Mary Thompson @ Carnegie Mellon
  72.  *    Added itPortType
  73.  *    Added itTidType
  74.  */
  75.  
  76. #ifndef    _TYPE_H
  77. #define    _TYPE_H
  78.  
  79. #define    EXPORT_BOOLEAN
  80. #include <mach/boolean.h>
  81. #include <sys/types.h>
  82. #include "string.h"
  83.  
  84. typedef u_int ipc_flags_t;
  85.  
  86. #define    flNone        (0x00)
  87. #define    flLong        (0x01)    /* IsLong specified */
  88. #define    flNotLong    (0x02)    /* NotIsLong specified */
  89. #define    flDealloc    (0x04)    /* Dealloc specified */
  90. #define    flNotDealloc    (0x08)    /* NotDealloc specified */
  91. #define    flMaybeDealloc    (0x10)    /* Dealloc[] specified */
  92. #define    flServerCopy    (0x20)    /* ServerCopy specified */
  93. #define    flCountInOut    (0x40)    /* CountInOut specified */
  94.  
  95. typedef enum dealloc {
  96.     d_NO,            /* do not deallocate */
  97.     d_YES,            /* always deallocate */
  98.     d_MAYBE            /* deallocate according to parameter */
  99. } dealloc_t;
  100.  
  101. /* Convert dealloc_t to TRUE/FALSE */
  102. #define    strdealloc(d)    (strbool(d == d_YES))
  103.  
  104. /*
  105.  * itName and itNext are internal fields (not used for code generation).
  106.  * They are only meaningful for types entered into the symbol table.
  107.  * The symbol table is a simple self-organizing linked list.
  108.  *
  109.  * The function itCheckDecl checks & fills in computed information.
  110.  * Every type actually used (pointed at by argType) is so processed.
  111.  *
  112.  * The itInName, itOutName, itSize, itNumber, itInLine, itLongForm,
  113.  * and itDeallocate fields correspond directly to mach_msg_type_t fields.
  114.  * For out-of-line variable sized types, itNumber is zero.  For
  115.  * in-line variable sized types, itNumber is the maximum size of the
  116.  * array.  itInName is the msgt_name value supplied to the kernel,
  117.  * and itOutName is the msgt_name value received from the kernel.
  118.  * Either or both may be MACH_MSG_TYPE_POLYMORPHIC, indicating a
  119.  * "polymorphic" msgt_name.  For itInName, this means the user
  120.  * supplies the value with an argument.  For itOutName, this means the
  121.  * the value is returned in an argument.
  122.  *
  123.  * The itInNameStr and itOutNameStr fields contain "printing" versions
  124.  * of the itInName and itOutName values.  The mapping from number->string
  125.  * is not into (eg, MACH_MSG_TYPE_UNSTRUCTURED/MACH_MSG_TYPE_BOOLEAN/
  126.  * MACH_MSG_TYPE_BIT).  These fields are used for code-generation and
  127.  * pretty-printing.
  128.  *
  129.  * itFlags contains the user's requests for itLongForm and itDeallocate
  130.  * values.  itCheckDecl takes it into account when setting itLongForm
  131.  * and itDeallocate, but they can be overridden (with a warning message).
  132.  *
  133.  * itTypeSize is the calculated size of the C type, in bytes.
  134.  * itPadSize is the size of any padded needed after the data field.
  135.  * itMinTypeSize is the minimum size of the data field, including padding.
  136.  * For variable-length inline data, it is zero.
  137.  *
  138.  * itUserType, itServerType, itTransType are the C types used in
  139.  * code generation.  itUserType is the C type passed to the user-side stub
  140.  * and used for msg declarations in the user-side stub.  itServerType
  141.  * is the C type used for msg declarations in the server-side stub.
  142.  * itTransType is the C type passed to the server function by the
  143.  * server-side stub.  Normally it differs from itServerType only when
  144.  * translation functions are defined.
  145.  *
  146.  * itInTrans and itOutTrans are translation functions.  itInTrans
  147.  * takes itServerType values and returns itTransType values.  itOutTrans
  148.  * takes itTransType vaulues and returns itServerType values.
  149.  * itDestructor is a finalization function applied to In arguments
  150.  * after the server-side stub calls the server function.  It takes
  151.  * itTransType values.  Any combination of these may be defined.
  152.  *
  153.  * The following type specification syntax modifies these values:
  154.  *    type new = old
  155.  *        ctype: name        // itUserType and itServerType
  156.  *        cusertype: itUserType
  157.  *        cservertype: itServerType
  158.  *        intran: itTransType itInTrans(itServerType)
  159.  *        outtran: itServerType itOutTrans(itTransType)
  160.  *        destructor: itDestructor(itTransType);
  161.  *
  162.  * At most one of itStruct and itString should be TRUE.  If both are
  163.  * false, then this is assumed to be an array type (msg data is passed
  164.  * by reference).  If itStruct is TRUE, then msg data is passed by value
  165.  * and can be assigned with =.  If itString is TRUE, then the msg_data
  166.  * is a null-terminated string, assigned with strncpy.  The itNumber
  167.  * value is a maximum length for the string; the msg field always
  168.  * takes up this much space.
  169.  *
  170.  * itVarArray means this is a variable-sized array.  If it is inline,
  171.  * then itStruct and itString are FALSE.  If it is out-of-line, then
  172.  * itStruct is TRUE (because pointers can be assigned).
  173.  *
  174.  * itIndefinite means this is an indefinite-length array - it may be sent
  175.  * either inline or out-of-line.  itNumber is assigned so that at most
  176.  * 2048 bytes are sent inline.
  177.  *
  178.  * itElement points to any substructure that the type may have.
  179.  * It is only used with variable-sized array types.
  180.  */
  181.  
  182. typedef struct ipc_type
  183. {
  184.     identifier_t itName;    /* Mig's name for this type */
  185.     struct ipc_type *itNext;    /* next type in symbol table */
  186.  
  187.     u_int itTypeSize;        /* size of the C type */
  188.     u_int itPadSize;        /* amount of padding after data */
  189.     u_int itMinTypeSize;    /* minimal amount of space occupied by data */
  190.  
  191.     u_int itInName;        /* name supplied to kernel in sent msg */
  192.     u_int itOutName;        /* name in received msg */
  193.     u_int itSize;
  194.     u_int itNumber;
  195.     boolean_t itInLine;
  196.     boolean_t itLongForm;
  197.     dealloc_t itDeallocate;
  198.  
  199.     string_t itInNameStr;    /* string form of itInName */
  200.     string_t itOutNameStr;    /* string form of itOutName */
  201.  
  202.     /* what the user wants, not necessarily what he gets */
  203.     ipc_flags_t itFlags;
  204.  
  205.     boolean_t itStruct;
  206.     boolean_t itString;
  207.     boolean_t itVarArray;
  208.     boolean_t itIndefinite;
  209.  
  210.     struct ipc_type *itElement;    /* may be NULL */
  211.  
  212.     identifier_t itUserType;
  213.     identifier_t itServerType;
  214.     identifier_t itTransType;
  215.  
  216.     identifier_t itInTrans;    /* may be NULL */
  217.     identifier_t itOutTrans;    /* may be NULL */
  218.     identifier_t itDestructor;    /* may be NULL */
  219. } ipc_type_t;
  220.  
  221. #define    itNULL        ((ipc_type_t *) 0)
  222.  
  223. extern ipc_type_t *itLookUp(/* identifier_t name */);
  224. extern void itInsert(/* identifier_t name, ipc_type_t *it */);
  225. extern void itTypeDecl(/* identifier_t name, ipc_type_t *it */);
  226.  
  227. extern ipc_type_t *itShortDecl(/* u_int inname, string_t instr,
  228.                   u_int outname, string_t outstr,
  229.                   u_int dfault */);
  230. extern ipc_type_t *itLongDecl(/* u_int inname, string_t instr,
  231.                  u_int outname, string_t outstr,
  232.                  u_int dfault,
  233.                  u_int size, ipc_flags_t flags */);
  234. extern ipc_type_t *itPrevDecl(/* identifier_t name */);
  235. extern ipc_type_t *itResetType(/* ipc_type_t *it */);
  236. extern ipc_type_t *itVarArrayDecl(/* u_int number, ipc_type_t *it */);
  237. extern ipc_type_t *itArrayDecl(/* u_int number, ipc_type_t *it */);
  238. extern ipc_type_t *itPtrDecl(/* ipc_type_t *it */);
  239. extern ipc_type_t *itStructDecl(/* u_int number, ipc_type_t *it */);
  240. extern ipc_type_t *itCStringDecl(/* u_int number, boolean_t varying */);
  241.  
  242. extern ipc_type_t *itRetCodeType;
  243. extern ipc_type_t *itDummyType;
  244. extern ipc_type_t *itTidType;
  245. extern ipc_type_t *itRequestPortType;
  246. extern ipc_type_t *itZeroReplyPortType;
  247. extern ipc_type_t *itRealReplyPortType;
  248. extern ipc_type_t *itWaitTimeType;
  249. extern ipc_type_t *itMsgOptionType;
  250. extern ipc_type_t *itMakeCountType();
  251. extern ipc_type_t *itMakePolyType();
  252. extern ipc_type_t *itMakeDeallocType();
  253.  
  254. extern void init_type();
  255.  
  256. extern void itCheckReturnType(/* identifier_t name, ipc_type_t *it */);
  257. extern void itCheckRequestPortType(/* identifier_t name, ipc_type_t *it */);
  258. extern void itCheckReplyPortType(/* identifier_t name, ipc_type_t *it */);
  259. extern void itCheckIntType(/* identifier_t name, ipc_type_t *it */);
  260.  
  261. extern ipc_flags_t itCheckFlags(/* ipc_flags_t name, identifier_t name */);
  262. extern dealloc_t itCheckDeallocate(/* ipc_type_t *it, ipc_flags_t flags,
  263.                       dealloc_t dfault, identifier_t name */);
  264. extern boolean_t itCheckIsLong(/* ipc_type_t *it, ipc_flags_t flags,
  265.                   boolean_t dfault, identifier_t name */);
  266.  
  267. #endif    _TYPE_H
  268.